package s_002_Bean_Life_Cycle.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Spring 内部对 BeanPostProcessor 的使用；
 *
 * @Value bean赋值；
 * @Autowired 注入其他组件；
 * @Async 异步方法;
 * @PostConstruct 生命周期注解功能；
 * @PreDestroy 生命周期注解功能；
 * ApplicationContextAware：让Bean可以使用IOC容器；===》ApplicationContextAwareProcessor
 * 等等。。。。。。
 */
@Component
public class Dog2 implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    public Dog2() {
        System.out.println("dog constructor...");
    }

    //对象创建并赋值之后调用
    @PostConstruct
    public void init() {
        System.out.println("Dog....@PostConstruct...");
    }

    //容器移除对象之前
    @PreDestroy
    public void detory() {
        System.out.println("Dog....@PreDestroy...");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
